package com.lsq.baseadmin.modules.manage.controller;


import com.lsq.baseadmin.modules.manage.entity.Department;
import com.lsq.baseadmin.modules.manage.service.DepartmentService;
import io.swagger.annotations.ApiOperation;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lsq
 * @since 2020-10-27
 */
@RestController
@RequestMapping("/department")
public class DepartmentController {

    private DepartmentService departmentService;

    public DepartmentController(DepartmentService departmentService) {
        this.departmentService = departmentService;
    }

    @ApiOperation("部门列表")
    @GetMapping("/list")
    public ResponseEntity list(Department department) {
        List<Department> list = departmentService.list(department);
        return ResponseEntity.ok(list);
    }

    @ApiOperation("部门添加")
    @PostMapping("/add")
    public ResponseEntity add(@RequestBody Department department) {
        departmentService.save(department);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation("部门修改")
    @PostMapping("/update")
    public ResponseEntity update(@RequestBody Department department) {
        departmentService.update(department);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation("部门修改状态")
    @PostMapping("/updateStatus")
    public ResponseEntity updateStatus(@RequestBody Department department) {
        departmentService.updateStatus(department);
        return new ResponseEntity(HttpStatus.OK);
    }

    @ApiOperation("部门删除")
    @PostMapping("/delete")
    public ResponseEntity delete(int id) {
        departmentService.removeById(id);
        return new ResponseEntity(HttpStatus.OK);
    }

}
